using System;
using System.IO;
using FireStarter.CodeGeneration;
using FireStarterModeller.BO;
using NUnit.Framework;

namespace FireStarter.Test.CodeGeneration
{
    [TestFixture]
    public class TestGeneratorBase : TestBase
    {
        protected static string TEST_PROJECTS_FOLDER = "TestProjects";
        
        [SetUp]
        public void SetupTest()
        {
            if (Directory.Exists(TEST_PROJECTS_FOLDER))
            {
                try
                {
                    Directory.Delete(TEST_PROJECTS_FOLDER, true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }

        #region Utility Methods

        protected static string GetRootedPath(string path)
        {
            if (Path.IsPathRooted(path)) return path;
            return Path.Combine(Environment.CurrentDirectory, path);
        }

        protected static string GetRandomProjectFileName()
        {
            return GetRandomProjectFileName(GetRandomString());
        }

        protected static string GetRandomProjectFileName(string projectName)
        {
            return Path.Combine(TEST_PROJECTS_FOLDER, string.Format("{0}\\{0}.csproj", projectName));
        }

        protected static ProjectFileManager CreateRandomProjectFile(string projectName)
        {
            if (projectName == null) throw new ArgumentNullException("projectName");
            string projectFileName = GetRootedPath(GetRandomProjectFileName(projectName));
            ProjectFileManager projectFileManager = new ProjectFileManager(projectFileName, OutputType.Library, CodeTemplateEnum.CSharpVisualStudio2005);
            projectFileManager.SaveProjectFile();
            return projectFileManager;
        }

        #endregion Utility Methods

    }
}
